<template>
	<div style="">
		<!-- <el-table id="treeTable" :data="tableData" style="width: 100%;margin-bottom: 20px;" row-key="task_xh" border
            default-expand-all :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
            v-loading="WitGlobal.treeLoading" @row-contextmenu="rightClick"> -->
		<el-table id="treeTable" :data="tableData" style="width: 100%;margin-bottom: 20px;" row-key="task_xh" border
			default-expand-all :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
			v-loading="WitGlobal.treeLoading" @row-contextmenu="rightClick">
			<el-table-column prop="task_xh" label="序号" width="120">
			</el-table-column>
			<el-table-column prop="task_name" label="任务名称" show-overflow-tooltip>
			</el-table-column>
			<el-table-column prop="task_status" label="任务状态" width="100">
			</el-table-column>
			<el-table-column prop="plan_start_date" label="计划开始日期" width="120">
			</el-table-column>
			<el-table-column prop="plan_end_date" label="计划完成日期" width="120">
			</el-table-column>
			<el-table-column prop="task_jhgqt" label="计划工期(天)" width="120">
			</el-table-column>
			<el-table-column prop="task_gjgzl" label="估计工作量(小时)" width="140">
			</el-table-column>
			<el-table-column prop="task_responder_id" label="责任人" width="100">
			</el-table-column>
			<el-table-column prop="task_shr_id" label="审核人" width="100">
			</el-table-column>
		</el-table>
		<div v-show="menuVisible" ref="menuRef">
			<div id="menu" class="menu">
				<div class="menu_item first">
					<el-button type="text" @click="addData">新增</el-button>
				</div>
				<div class="line"></div>
				<!-- <div class="menu_item" @click="newWindowOpenLink">在新窗口中打开链接</div> -->
				<div class="menu_item second">
					<el-button type="text" :disabled="form.flag_import == 1" @click="editData">编辑</el-button>
				</div>
				<div class="line"></div>
				<div class="menu_item second">
					<el-button type="text" :disabled="form.flag_import == 1" @click="deleteData">删除</el-button>
				</div>
			</div>
		</div>
		<el-dialog :title="dialogTitle" :visible.sync="dialogFormVisible" :append-to-body="true" width="560px"
			style="padding-right: 50px;">
			<el-form :model="form">
				<el-form-item label="序号" :label-width="formLabelWidth">
					<el-input v-model="form.task_xh" autocomplete="off"></el-input>
				</el-form-item>
				<el-form-item label="任务名称" :label-width="formLabelWidth">
					<el-input v-model="form.task_name" autocomplete="off"></el-input>
				</el-form-item>
				<el-form-item label="计划开始日期" :label-width="formLabelWidth">
					<el-date-picker v-model="form.plan_start_date" autocomplete="off" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"></el-date-picker>
				</el-form-item>
				<el-form-item label="计划完成日期" :label-width="formLabelWidth">
					<el-date-picker v-model="form.plan_end_date" autocomplete="off" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"></el-date-picker>
				</el-form-item>
				<el-form-item label="计划工期(天)" :label-width="formLabelWidth">
					<el-input v-model="form.task_jhgqt" autocomplete="off"></el-input>
				</el-form-item>
				<el-form-item label="估计工作量(小时)" :label-width="formLabelWidth">
					<el-input v-model="form.task_gjgzl" autocomplete="off"></el-input>
				</el-form-item>
				<el-form-item label="责任人" :label-width="formLabelWidth">
					<el-input v-model="form.task_responder_id" autocomplete="off"></el-input>
				</el-form-item>
				<el-form-item label="审核人" :label-width="formLabelWidth">
					<el-input v-model="form.task_shr_id" autocomplete="off"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dialogFormVisible = false">取 消</el-button>
				<el-button type="primary" @click="handleOK">确 定</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	export default {
    name: 'App',
    props: { value: String },
    components: {},
    data() {
        return {
            formLabelWidth: '120px',
            dialogTitle: "新增",
            dialogFormVisible: false,
            form: {
                task_xh: '',
                task_name: '',
                plan_start_date: '',
                plan_end_date: '',
                task_jhgqt: "",
                task_gjgzl: "",
                task_responder_id: '',
                task_shr_id: ''
            },
            userInfo: {},
            tableData: [],
            menuVisible: false,
            menuPosition: { x: 0, y: 0 },
            tableDataOrgin: "",
            treeData: this.WitGlobal.treeTableData
            // tableDataOrgin: '[{"序号":"1","计划完成日期":"","审核人":"","责任人":"","计划开始日期":"","任务名称":"M1-项目准备阶段","计划工期(天)":"","估计工作量(小时)":""},{"序号":"1.1","计划完成日期":"2024-07-15","审核人":"喻振江","责任人":"喻振江","计划开始日期":"2024-07-15","任务名称":"编写实施计划","计划工期(天)":"1.0","估计工作量(小时)":"8.0"},{"序号":"1.2","计划完成日期":"2024-07-16","审核人":"喻振江","责任人":"喻振江","计划开始日期":"2024-07-16","任务名称":"实施计划与客户沟通确认","计划工期(天)":"1.0","估计工作量(小时)":"1.0"},{"序号":"1.3","计划完成日期":"2024-07-17","审核人":"喻振江","责任人":"喻振江","计划开始日期":"2024-07-16","任务名称":"项目启动会议材料准备","计划工期(天)":"1.0","估计工作量(小时)":"1.0"},{"序号":"1.1.1","计划完成日期":"2024-07-17","审核人":"喻振江","责任人":"喻振江","计划开始日期":"2024-07-16","任务名称":"双方项目组成员确认","计划工期(天)":"0.5","估计工作量(小时)":"4.0"},{"序号":"1.5","计划完成日期":"2024-07-17","审核人":"喻振江","责任人":"喻振江","计划开始日期":"2024-07-17","任务名称":"项目启动会议召开","计划工期(天)":"0.5","估计工作量(小时)":"1.0"},{"序号":"1.6","计划完成日期":"2024-07-20","审核人":"喻振江","责任人":"喻振江","计划开始日期":"2024-07-19","任务名称":"阶段确认","计划工期(天)":"1.0","估计工作量(小时)":"2.0"},{"序号":"2","计划完成日期":"","审核人":"","责任人":"","计划开始日期":"","任务名称":"M2-项目策划阶段","计划工期(天)":"","估计工作量(小时)":""},{"序号":"2.1","计划完成日期":"2024-07-22","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-07-22","任务名称":"需求调研计划编制","计划工期(天)":"0.5","估计工作量(小时)":"1.0"},{"序号":"2.2","计划完成日期":"2024-07-24","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-07-23","任务名称":"基础数据搜集模板","计划工期(天)":"1.0","估计工作量(小时)":"2.0"},{"序号":"2.3","计划完成日期":"2024-07-26","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-07-24","任务名称":"编写业务调研报告","计划工期(天)":"2.0","估计工作量(小时)":"14.0"},{"序号":"2.4","计划完成日期":"2024-08-01","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-07-24","任务名称":"业务需求访谈","计划工期(天)":"1.0","估计工作量(小时)":"12.0"},{"序号":"2.5","计划完成日期":"2024-08-07","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-02","任务名称":"规划与编写业务方案","计划工期(天)":"16.0","估计工作量(小时)":"30.0"},{"序号":"2.6","计划完成日期":"2024-08-09","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-08","任务名称":"业务方案评审","计划工期(天)":"1.0","估计工作量(小时)":"4.0"},{"序号":"2.7","计划完成日期":"2024-08-10","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-10","任务名称":"业务调研报告、业务方案客户确认、签字","计划工期(天)":"1.0","估计工作量(小时)":"4.0"},{"序号":"2.8","计划完成日期":"2024-08-12","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-11","任务名称":"项目经理提出硬件采购计划","计划工期(天)":"3.0","估计工作量(小时)":"1.0"},{"序号":"2.9","计划完成日期":"2024-09-08","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-19","任务名称":"按照合同要求完成采购，并现场与客户进行收货确认","计划工期(天)":"1.0","估计工作量(小时)":"3.0"},{"序号":"2.10","计划完成日期":"2024-08-15","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-10","任务名称":"组织与人员基础数据梳理（工厂组织、车间/产线/工位、部门人员信息）","计划工期(天)":"13.0","估计工作量(小时)":"16.0"},{"序号":"2.11","计划完成日期":"2024-08-15","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-10","任务名称":"物料基础数据梳理（物料分类、物料信息、产品BOM）","计划工期(天)":"12.0","估计工作量(小时)":"36.0"},{"序号":"2.12","计划完成日期":"2024-08-15","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-10","任务名称":"产品工艺数据整理（按车间整理工序、工艺路线、产品工艺路线）","计划工期(天)":"7.0","估计工作量(小时)":"8.0"},{"序号":"2.13","计划完成日期":"2024-08-15","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-10","任务名称":"客户基础数据整理","计划工期(天)":"10.0","估计工作量(小时)":"8.0"},{"序号":"2.14","计划完成日期":"2024-08-15","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-10","任务名称":"供应商、物料采购单价等基础数据整理","计划工期(天)":"10.0","估计工作量(小时)":"8.0"},{"序号":"2.15","计划完成日期":"2024-08-15","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-10","任务名称":"质量基础数据整理（检验标准、检验项、缺陷项）","计划工期(天)":"13.0","估计工作量(小时)":"36.0"},{"序号":"3.0","计划完成日期":"","审核人":"","责任人":"","计划开始日期":"","任务名称":"M3-项目配置阶段","计划工期(天)":"","估计工作量(小时)":""},{"序号":"3.1","计划完成日期":"2024-08-11","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-10","任务名称":"系统部署","计划工期(天)":"4.0","估计工作量(小时)":"8.0"},{"序号":"3.2","计划完成日期":"2024-08-16","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-11","任务名称":"组织与人员基础数据系统维护","计划工期(天)":"30.0","估计工作量(小时)":"40.0"},{"序号":"3.3","计划完成日期":"2024-08-16","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-11","任务名称":"物料基础数据系统维护","计划工期(天)":"25.0","估计工作量(小时)":"80.0"},{"序号":"3.4","计划完成日期":"2024-08-16","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-11","任务名称":"产品工艺数据系统维护","计划工期(天)":"10.0","估计工作量(小时)":"40.0"},{"序号":"3.5","计划完成日期":"2024-08-16","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-11","任务名称":"客户基础数据系统维护","计划工期(天)":"4.0","估计工作量(小时)":"8.0"},{"序号":"3.6","计划完成日期":"2024-08-16","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-11","任务名称":"供应商、物料采购单价等基础数据系统维护","计划工期(天)":"30.0","估计工作量(小时)":"40.0"},{"序号":"3.7","计划完成日期":"2024-08-16","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-11","任务名称":"质量基础数据系统维护","计划工期(天)":"25.0","估计工作量(小时)":"80.0"},{"序号":"3.8","计划完成日期":"2024-08-16","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-16","任务名称":"系统业务数据测试","计划工期(天)":"10.0","估计工作量(小时)":"40.0"},{"序号":"3.9","计划完成日期":"2024-08-12","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-11","任务名称":"与客户沟通硬件安装位置","计划工期(天)":"4.0","估计工作量(小时)":"8.0"},{"序号":"3.10","计划完成日期":"2024-09-01","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-12","任务名称":"客户方完成硬件安装位置的电源布线及网络接通","计划工期(天)":"30.0","估计工作量(小时)":"40.0"},{"序号":"3.11","计划完成日期":"2024-09-09","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-09-02","任务名称":"硬件上架及调试确认","计划工期(天)":"25.0","估计工作量(小时)":"80.0"},{"序号":"3.12","计划完成日期":"2024-09-10","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-09-09","任务名称":"阶段确认","计划工期(天)":"4.0","估计工作量(小时)":"8.0"},{"序号":"4.0","计划完成日期":"","审核人":"","责任人":"","计划开始日期":"","任务名称":"M4-培训推广阶段","计划工期(天)":"","估计工作量(小时)":""},{"序号":"4.1","计划完成日期":"2024-08-20","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-16","任务名称":"用户测试","计划工期(天)":"1.0","估计工作量(小时)":"1.0"},{"序号":"4.2","计划完成日期":"2024-08-31","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-21","任务名称":"主数据管理业务培训与验证","计划工期(天)":"2.0","估计工作量(小时)":"3.0"},{"序号":"4.3","计划完成日期":"2024-08-31","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-21","任务名称":"销售管理业务培训与验证","计划工期(天)":"2.0","估计工作量(小时)":"16.0"},{"序号":"4.4","计划完成日期":"2024-08-31","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-21","任务名称":"计划管理业务培训与验证","计划工期(天)":"2.0","估计工作量(小时)":"16.0"},{"序号":"4.5","计划完成日期":"2024-08-31","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-21","任务名称":"采购管理业务培训与验证","计划工期(天)":"2.0","估计工作量(小时)":"3.0"},{"序号":"4.6","计划完成日期":"2024-08-31","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-21","任务名称":"生产管理业务培训与验证","计划工期(天)":"2.0","估计工作量(小时)":"16.0"},{"序号":"4.7","计划完成日期":"2024-08-31","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-21","任务名称":"设备联网业务培训与验证","计划工期(天)":"2.0","估计工作量(小时)":"4.0"},{"序号":"4.8","计划完成日期":"2024-08-31","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-21","任务名称":"设备管理业务培训与验证","计划工期(天)":"2.0","估计工作量(小时)":"24.0"},{"序号":"4.9","计划完成日期":"2024-08-31","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-21","任务名称":"计件（时）工资管理业务培训与验证","计划工期(天)":"2.0","估计工作量(小时)":"160.0"},{"序号":"4.10","计划完成日期":"2024-08-31","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-21","任务名称":"工模管理业务培训与验证","计划工期(天)":"1.0","估计工作量(小时)":"4.0"},{"序号":"4.11","计划完成日期":"2024-08-31","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-21","任务名称":"质量管理业务培训与验证","计划工期(天)":"3.0","估计工作量(小时)":"20.0"},{"序号":"4.12","计划完成日期":"2024-08-31","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-21","任务名称":"智能报表业务培训与验证","计划工期(天)":"1.0","估计工作量(小时)":"8.0"},{"序号":"4.13","计划完成日期":"2024-08-31","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-08-21","任务名称":"库存管理业务培训与验证","计划工期(天)":"1.0","估计工作量(小时)":"24.0"},{"序号":"4.14","计划完成日期":"2024-09-30","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-09-01","任务名称":"主数据管理业务上线运行","计划工期(天)":"0.5","估计工作量(小时)":"1.0"},{"序号":"4.15","计划完成日期":"2024-09-30","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-09-01","任务名称":"销售管理业务上线运行","计划工期(天)":"0.5","估计工作量(小时)":"1.5"},{"序号":"4.16","计划完成日期":"2024-09-30","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-09-01","任务名称":"计划管理业务上线运行","计划工期(天)":"0.5","估计工作量(小时)":"2.0"},{"序号":"4.17","计划完成日期":"2024-09-30","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-09-01","任务名称":"采购管理业务上线运行","计划工期(天)":"0.5","估计工作量(小时)":"2.0"},{"序号":"4.18","计划完成日期":"2024-09-30","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-09-01","任务名称":"生产管理业务上线运行","计划工期(天)":"0.5","估计工作量(小时)":"1.5"},{"序号":"4.19","计划完成日期":"2024-09-30","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-09-01","任务名称":"设备联网业务上线运行","计划工期(天)":"0.5","估计工作量(小时)":"4.0"},{"序号":"4.20","计划完成日期":"2024-09-30","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-09-01","任务名称":"设备管理业务上线运行","计划工期(天)":"0.5","估计工作量(小时)":"2.0"},{"序号":"4.21","计划完成日期":"2024-09-30","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-09-01","任务名称":"计件（时）工资管理业务上线运行","计划工期(天)":"0.5","估计工作量(小时)":"2.0"},{"序号":"4.22","计划完成日期":"2024-09-30","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-09-01","任务名称":"工模管理业务上线运行","计划工期(天)":"0.5","估计工作量(小时)":"2.0"},{"序号":"4.23","计划完成日期":"2024-09-30","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-09-01","任务名称":"质量管理业务上线运行","计划工期(天)":"15.0","估计工作量(小时)":"80.0"},{"序号":"4.24","计划完成日期":"2024-09-30","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-09-01","任务名称":"智能报表业务上线运行","计划工期(天)":"15.0","估计工作量(小时)":"80.0"},{"序号":"4.25","计划完成日期":"2024-09-30","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-09-01","任务名称":"库存管理业务上线运行","计划工期(天)":"15.0","估计工作量(小时)":"80.0"},{"序号":"4.26","计划完成日期":"2024-10-01","审核人":"喻振江","责任人":"郭吉野","计划开始日期":"2024-09-30","任务名称":"客户完成上线确认签字","计划工期(天)":"15.0","估计工作量(小时)":"80.0"},{"序号":"5.0","计划完成日期":"","审核人":"","责任人":"","计划开始日期":"","任务名称":"M5-项目验收阶段","计划工期(天)":"","估计工作量(小时)":""},{"序号":"5.1","计划完成日期":"2024-09-30","审核人":"喻振江","责任人":"喻振江","计划开始日期":"2024-09-01","任务名称":"上线支持","计划工期(天)":"15.0","估计工作量(小时)":"30.0"},{"序号":"5.2","计划完成日期":"2024-10-05","审核人":"喻振江","责任人":"喻振江","计划开始日期":"2024-10-01","任务名称":"项目验收总结报告","计划工期(天)":"1.0","估计工作量(小时)":"30.0"},{"序号":"5.3","计划完成日期":"2024-10-11","审核人":"喻振江","责任人":"喻振江","计划开始日期":"2024-10-06","任务名称":"项目交接","计划工期(天)":"1.0","估计工作量(小时)":"10.0"},{"序号":"5.4","计划完成日期":"2024-10-15","审核人":"喻振江","责任人":"喻振江","计划开始日期":"2024-10-12","任务名称":"项目验收","计划工期(天)":"0.5","估计工作量(小时)":"4.0"}]',
        }
    },
    watch: {
        value() {
            console.log(123212321321);
            this.$forceUpdate();
        }
    },
    created() {
        // console.log(JSON.parse());

        // console.log(this.WitGlobal.user.getUserInfo());
        // this.userInfo = this.WitGlobal.user.getUserInfo();
    },
    mounted() {
        this.tableDataOrgin = this.WitGlobal.treeTableData;
        if (this.tableDataOrgin)
            this.handleData(this.tableDataOrgin)
        document.addEventListener('click', this.bodyCloseMenu)
    },
    beforeDestroy() {
        document.removeEventListener('click', this.bodyCloseMenu)
    },
    methods: {
        addData() {
            this.form = {
                f_id: this.uuid(),
                task_xh: '',
                task_name: '',
                plan_start_date: '',
                plan_end_date: '',
                task_jhgqt: "",
                task_gjgzl: "",
                task_responder_id: '',
                task_shr_id: '',
                flag_import: 0
            };
            this.dialogFormVisible = true;
            this.dialogTitle = "新增";
        },
        editData() {
            this.dialogFormVisible = true;
            this.dialogTitle = "编辑";
        },
        deleteData() {

            this.WitGlobal.requestCode("XM.project.db.project.selectWeekLyToOnePlanTask", { task_id: this.form.f_id }).then((res) => {
                if (res.code == 200 && res.data) {
                    if (res.data.length > 0) {
                        this.$alert('该任务已绑定周计划, 不可删除', '提示', {
                            confirmButtonText: '确定',
                            type: 'warning'
                        })
                    } else {
                        this.$confirm('此操作保存后将删除该任务, 是否继续?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(() => {
                            this.WitGlobal.treeTableData = this.WitGlobal.treeTableData.filter(item => {
                                return item.f_id !== this.form.f_id
                            })
                            this.tableDataOrgin = this.WitGlobal.treeTableData;
                            if (this.tableDataOrgin)
                                this.handleData(this.tableDataOrgin)
                        }).catch(() => {
                        });
                    }
                }
            })
        },
        handleOK() {
            if (this.dialogTitle == "新增")
                this.WitGlobal.treeTableData.push(this.form);
            if (this.dialogTitle == "编辑")
                this.WitGlobal.treeTableData = this.WitGlobal.treeTableData.map(item => {
                    if (item.f_id == this.form.f_id)
                        return { ...this.form }
                    else
                        return item
                })
            this.tableDataOrgin = this.WitGlobal.treeTableData;
            if (this.tableDataOrgin)
                this.handleData(this.tableDataOrgin)
            this.dialogFormVisible = false;
            // this.$forceUpdate()
        },
        rightClick(row, column, event) {
            this.menuVisible = false
            this.menuVisible = true
            var menu = document.querySelector('#menu')
            event.preventDefault();  // 阻止浏览器默认右键事件
            menu.style.left = event.x - 4 + 'px'
            menu.style.top = event.y - 4 + 'px'
            this.form = row
        },
        bodyCloseMenu(e) {
            let self = this
            if (this.$refs.menuRef && !this.$refs.menuRef.contains(e.target)) {
                if (self.menuVisible === true) {
                    self.menuVisible = false
                }
            }
        },
        handleData(data) {
            // let copyData = JSON.parse(JSON.stringify(JSON.parse(data)));
            let copyData = JSON.parse(JSON.stringify(data));
            let newData = copyData.map(item => this.convertKeysToPinyin(item));
            console.log("handleData", JSON.stringify(newData));

            const map = new Map();

            // 创建树形结构
            newData.forEach(item => {
                item.task_xh = this.removeTrailingZero(item.task_xh);
                item.children = [];
                map.set(item.task_xh, item);
            });


            // 按照 task_xh 排序
            newData.sort((a, b) => {
                // 将 task_xh 拆分为主版本和子版本
                const [aMain, aSub] = a.task_xh.split('.').map(Number);
                const [bMain, bSub] = b.task_xh.split('.').map(Number);

                // 先按主版本排序，再按子版本排序
                if (aMain !== bMain) {
                    return aMain - bMain;
                } else {
                    return aSub - bSub;
                }
            });

            // console.log(JSON.stringify(newData));
            
            const tree = [];

            newData.forEach(item => {
                const parentXh = this.getParentXh(item.task_xh);
                const parent = map.get(parentXh);

                if (parent) {
                    parent.children.push(item);
                } else {
                    tree.push(item); // 如果没有父节点，说明是根节点
                }
            });

            this.tableData = this.setTaskStatus(tree);
            this.$forceUpdate()
            // console.log(JSON.stringify(this.tableData));

        },
        setTaskStatus(data, isTopLevel = true) {
            data.forEach(task => {
                // 如果是顶级任务，则不设置 task_status
                if (!isTopLevel && (!task.hasOwnProperty('task_status') || task.task_status == '')) {
                    task.task_status = '未启动';  // 对于子任务，设置 task_status 为 '未启动'
                }
                // 如果有子任务，则递归处理
                if (task.children && task.children.length > 0) {
                    this.setTaskStatus(task.children, false);  // 递归时，传递 false 表示子任务
                }
            });
            return data;
        },
        uuid() {
            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
                // 生成一个随机数 r 在 [0, 15] 范围内
                const r = Math.random() * 16 | 0;

                // 如果是 'y'，则设置为 8、9、A 或 B 来符合 UUID v4 的规范
                const v = c === 'x' ? r : (r & 0x3 | 0x8);

                // 返回生成的字符
                return v.toString(16);
            });
        },
        removeTrailingZero(task_xh) {
            if (task_xh.endsWith('.0')) {
                return task_xh.slice(0, -2); // 去掉末尾的 .0
            }
            return task_xh;
        },
        // 获取父节点的序号，假设父节点的序号是当前序号去掉最后一位的部分
        getParentXh(task_xh) {
            const parts = task_xh.split('.');
            parts.pop();  // 去掉最后一位，获得父节点序号
            return parts.join('.') || '0'; // 根节点没有父节点，返回 '0'
        },
        convertKeysToPinyin(obj) {
            const keyMap = {
                "序号": "task_xh",
                "任务状态": "task_status",
                // "审核人": "task_shr_id",
                // "责任人": "task_responder_id",
                "计划开始日期": "plan_start_date",
                "计划完成日期": "plan_end_date",
                "任务名称": "task_name",
                "计划工期(天)": "task_jhgqt",
                "估计工作量(小时)": "task_gjgzl"
            };
            const newObj = {};

            // 遍历原对象的每一个键值对
            for (const key in obj) {
                if (keyMap[key]) {
                    // 如果映射关系存在，使用对应的拼音首字母缩写
                    newObj[keyMap[key]] = obj[key];
                } else {
                    // 如果没有映射关系，保持原来的key
                    newObj[key] = obj[key];
                }
            }
            return newObj;
        }
    }
};
</script>

<style lang="scss">
	#treeTable .el-table__row .el-table__expand-icon {
		margin-right: 0px !important;
	}

	.el-table .el-table__expand-icon {
		display: inline-block !important;
		width: 30px !important;
	}

	.el-table .el-table__placeholder {
		width: 30px !important;
	}

	.menu {
		position: fixed;
		border-radius: 3px;
		border: 1px solid #E4E7ED;
		box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
		background-color: #FFF;
		/* padding: 8px 0; */
		z-index: 9;
	}

	.menu_item {
		// display: block;
		padding: 5px 30px 0px 30px;
		font-size: 12px;
		white-space: nowrap;
		cursor: pointer;
	}

	.menu_item:hover {
		background-color: #eee;
	}

	.first {
		padding-bottom: 5px;
	}

	.second {
		padding-top: 5px;
	}

	.line {
		border-bottom: 1px solid #E4E7ED;
	}

	.el-dialog__body {
		padding: 16px 60px 0px 32px;
	}

	.el-table .cell.el-tooltip {
		display: block !important;
		white-space: nowrap !important;
		overflow: hidden !important;
		text-overflow: ellipsis !important;
	}
</style>